import { deleteByPrimaryKeyForProUserDept,selectByPrimaryKeyForProUserDept, insertForProUserDept, updateForProUserDept, deleteByMapForProUserDept,updateByMapForProUserDept, getOneForProUserDept,getAllForProUserDept,queryPageForProUserDept, countForProUserDept, insertBatchForProUserDept, deleteBatchForProUserDept,updateBatchForProUserDept,getProDeptTreeByLevelCode,getPageProUserByDeptCode,getProDeptTreeByParentid,insertForProDept,updateForProDept,deleteByPrimaryKeyForProDept,queryPageForProUser,updateChangeTargetNodeWithSourceNodeForProDept } from '@/services/system/api_prouserdept';


export default {
    namespace: 'proprouserdept',

    state: {
        data: {
            list: [],
            pagination: {},
        },
        deptTree: {
        	list: []
        },
        recorddata: {
            datarecord:{},
            message:null,
            success: false,
        },
    },

    effects: {
            *delete_by_primarykey_for_proprouserdept({ payload }, { call, put }) {
                const response = yield call(deleteByPrimaryKeyForProUserDept, payload);
                yield put({
                    type: 'deleteByPrimaryKeyForProUserDept',
                    payload: response,
                });
            },
            *select_by_primarykey_for_proprouserdept({ payload, callback }, { call, put }) {
                const response = yield call(selectByPrimaryKeyForProUserDept, payload);
                yield put({
                    type: 'selectByPrimaryKeyForProUserDept',
                    payload: response,
                });
                if (callback) callback();
            },
            *insert_for_proprouserdept({ payload, callback }, { call, put }) {
                const response = yield call(insertForProUserDept, payload);
                yield put({
                    type: 'insertForProUserDept',
                    payload: response,
                });
                if (callback) callback();
            },
            *update_for_proprouserdept({ payload, callback }, { call, put }) {
                const response = yield call(updateForProUserDept, payload);
                yield put({
                    type: 'updateForProUserDept',
                    payload: response,
                });
                if (callback) callback();
            },
            *delete_by_map_for_proprouserdept({ payload, callback }, { call, put }) {
                const response = yield call(deleteByMapForProUserDept, payload);
                yield put({
                    type: 'deleteByMapForProUserDept',
                    payload: response,
                });
                if (callback) callback();
            },
            *update_by_map_for_proprouserdept({ payload, callback }, { call, put }) {
                const response = yield call(updateByMapForProUserDept, payload);
                yield put({
                    type: 'updateByMapForProUserDept',
                    payload: response,
                });
                if (callback) callback();
            },
            *get_one_for_proprouserdept({ payload, callback }, { call, put }) {
                const response = yield call(getOneForProUserDept, payload);
                yield put({
                    type: 'getOneForProUserDept',
                    payload: response,
                });
                if (callback) callback();
            },
            *get_all_for_proprouserdept({ payload, callback }, { call, put }) {
                const response = yield call(getAllForProUserDept, payload);
                yield put({
                    type: 'getAllForProUserDept',
                    payload: response,
                });
                if (callback) callback();
            },
            *count_for_proprouserdept({ payload, callback }, { call, put }) {
                const response = yield call(countForProUserDept, payload);
                yield put({
                    type: 'countForProUserDept',
                    payload: response,
                });
                if (callback) callback();
            },
            *insert_batch_for_proprouserdept({ payload, callback }, { call, put }) {
                const response = yield call(insertBatchForProUserDept, payload);
                yield put({
                    type: 'insertBatchForProUserDept',
                    payload: response,
                });
                if (callback) callback();
            },
            *delete_batch_for_proprouserdept({ payload, callback }, { call, put }) {
                const response = yield call(deleteBatchForProUserDept, payload);
                yield put({
                    type: 'deleteBatchForProUserDept',
                    payload: response,
                });
                if (callback) callback();
            },
            *update_batch_for_proprouserdept({ payload, callback }, { call, put }) {
                const response = yield call(updateBatchForProUserDept, payload);
                yield put({
                    type: 'updateBatchForProUserDept',
                    payload: response,
                });
                if (callback) callback();
            },
            *get_pro_depttree_by_levelcode({ payload, callback }, { call, put }) {
                const response = yield call(getProDeptTreeByLevelCode, payload);
                yield put({
                    type: 'getProDeptTreeByLevelCode',
                    payload: response,
                });
                if (callback) callback();
            },
            *get_page_prouser_by_deptcode({ payload, callback }, { call, put }) {
                const response = yield call(getPageProUserByDeptCode, payload);
                yield put({
                    type: 'getPageProUserByDeptCode',
                    payload: response,
                });
                if (callback) callback();
            },
            *get_prodepttree_by_parentid({ payload, callback }, { call, put }) {
                const response = yield call(getProDeptTreeByParentid, payload);
                yield put({
                    type: 'getProDeptTreeByParentid',
                    payload: response,
                });
                if (callback) callback(response);
            },
            *insert_for_prodept({ payload, callback }, { call, put }) {
                const response = yield call(insertForProDept, payload);
                yield put({
                    type: 'insertForProDept',
                    payload: response,
                });
                
                const responseUser = yield call(queryPageForProUser, {});
                yield put({
                    type: 'queryPageForProUser',
                    payload: responseUser,
                });
                if (callback) callback(response);
            },
            *update_for_prodept({ payload, callback }, { call, put }) {
                const response = yield call(updateForProDept, payload);
                yield put({
                    type: 'updateForProDept',
                    payload: response,
                });
               
                
                const responseUser = yield call(queryPageForProUser, {});
                yield put({
                    type: 'queryPageForProUser',
                    payload: responseUser,
                });
                if (callback) callback(response);
            },
            *delete_by_primarykey_for_prodept({ payload, callback }, { call, put }) {
                const response = yield call(deleteByPrimaryKeyForProDept, payload);
                yield put({
                    type: 'deleteByPrimaryKeyForProDept',
                    payload: response,
                });
                
                const responseUser = yield call(queryPageForProUser, {});
                yield put({
                    type: 'queryPageForProUser',
                    payload: responseUser,
                });
                if (callback) callback(response);
            },
            *update_change_target_node_with_source_node_pro_dept({ payload, callback }, { call, put }) {
                const response = yield call(updateChangeTargetNodeWithSourceNodeForProDept, payload);
                yield put({
                    type: 'updateChangeTargetNodeWithSourceNodeForProDept',
                    payload: response,
                });
                
                if (callback) callback(response);
            },
            },

    reducers: {
        deleteByPrimaryKeyForProUserDept(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        selectByPrimaryKeyForProUserDept(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertForProUserDept(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateForProUserDept(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteByMapForProUserDept(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateByMapForProUserDept(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getOneForProUserDept(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getAllForProUserDept(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        countForProUserDept(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        insertBatchForProUserDept(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteBatchForProUserDept(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateBatchForProUserDept(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        
        getProDeptTreeByLevelCode(state, action) {
            return {
                ...state,
                deptTree: action.payload,
            };
        },
        getPageProUserByDeptCode(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        getProDeptTreeByParentid(state, action) {
            return {
                ...state,
                deptTree: action.payload,
            };
        },
        insertForProDept(state, action) {
            return {
                ...state,
                recorddata: action.payload,
            };
        },
        updateForProDept(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        deleteByPrimaryKeyForProDept(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        queryPageForProUser(state, action) {
            return {
                ...state,
                data: action.payload,
            };
        },
        updateChangeTargetNodeWithSourceNodeForProDept(state, action) {
            return {
                ...state,
                recorddata: action.payload,
            };
        },
    },
};
